<template>
    <div class="resetpassword">
        <div class="form">
            <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px">
                <el-form-item label="用户账号:" prop="username">
                    <el-input v-model="ruleForm.username"></el-input>
                </el-form-item>
                <el-form-item label="新密码:" prop="newpassword">
                    <el-input v-model="ruleForm.newpassword" show-password></el-input>
                </el-form-item>
                <el-form-item label="确认密码:" prop="surepassword" >
                    <el-input v-model="ruleForm.surepassword" show-password></el-input>
                </el-form-item>
                <el-form-item style="margin-top:50px;">
                    <el-button
                        type="warning"
                        @click="submitForm('ruleForm')"
                        size="small"
                        style="width:140px;"
                    >确定</el-button>
                </el-form-item>
            </el-form>
        </div>
    </div>
</template>
<script>
import { mapState, mapActions, mapMutations } from "vuex";
import Bus from '../bus.js';
export default {
    data() {
        return {
            ruleForm: {
                username: "",
                newpassword: "",
                surepassword: ""
            },
            rules: {
                username: [
                    {
                        required: true,
                        message: "请输入用户账号",
                        trigger: "change"
                    },
                    {
                        min: 5,
                        max: 15,
                        message: "长度在 5 到 15 个字符",
                        trigger: "blur"
                    }
                ],
                newpassword: [
                    {
                        required: true,
                        message: "请输入新密码",
                        trigger: "blur"
                    },
                    {
                        min: 5,
                        max: 15,
                        message: "长度在 5 到 15 个字符",
                        trigger: "blur"
                    }
                ],
                surepassword: [
                    {
                        required: true,
                        message: "请确认密码",
                        trigger: "blur"
                    },
                    {
                        min: 5,
                        max: 15,
                        message: "长度在 5 到 15 个字符",
                        trigger: "blur"
                    }
                ]
            },
        };
    },
    components: {},
    methods: {
        //账户密码重置
        submitForm(formName) {
            this.$refs[formName].validate(valid => {
                if (valid) {
                    this.$axios({
                        method: 'post',
                        url: '/index/administrator/resetpassword',
                        data: {
                            password: '',
                            newpassword: ''
                        }
                    }).then((res) => {
                        this.$message("提交成功");
                        this.$router.push({ name: "Dzzgl" });
                        // this.setCurrentMenu({
                        //     name: "党组织管理",
                        //     url: "Dzzgl"
                        // });
                    }).catch((err) => {
                        this.$message.error("提交失败");
                    })
                } else {
                    this.$message.error("提交失败");
                }
            });
        },
    }
};
</script>

<style lang="scss">
.resetpassword {
    .form {
        margin: 100px 0 0 200px;
        .el-form-item__content {
            width: 500px;
        }
    }
}
</style>
